//
//  UITextField+Add.swift
//  HHSwift
//
//  Created by qk-huahong on 2019/6/19.
//  Copyright © 2019 huahong. All rights reserved.
//

import Foundation
extension UITextField{
   
    func selectAllText() {
        
        let range:UITextRange? = self.textRange(from: self.beginningOfDocument, to: self.endOfDocument)
        self.selectedTextRange = range
        
    }
    
    func setSelectedRange(range:NSRange) {
        let beginning:UITextPosition = self.beginningOfDocument
        let startPosition = self.position(from: beginning, offset: range.location)
        let endPosition = self.position(from: beginning, offset: NSMaxRange(range))
        
        guard let start = startPosition else { return  }
        guard let end = endPosition else { return  }
        let selectionRange:UITextRange? = self.textRange(from: start, to: end)
        
        self.selectedTextRange = selectionRange
        
    }
}
